package com.ytjj.qmyx.admin.controller.supplyChain;

import com.ytjj.common.api.CommonPage;
import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.model.Admin;
import com.ytjj.qmyx.admin.model.request.OrderProblemCommitRequest;
import com.ytjj.qmyx.admin.model.request.OrderProblemListRequest;
import com.ytjj.qmyx.admin.model.request.OrderProblemReplyRequest;

import com.ytjj.qmyx.admin.model.response.OrderProblemDetailResponse;
import com.ytjj.qmyx.admin.model.response.OrderProblemExportResponse;
import com.ytjj.qmyx.admin.model.response.OrderProblemListResponse;
import com.ytjj.qmyx.admin.service.OrderProblemService;
import com.ytjj.qmyx.admin.utils.UserUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单问题相关接口
 */
@RestController
@RequestMapping("/orderProblem")
@Slf4j
public class OrderProblemController {
    @Resource
    private OrderProblemService orderProblemService;

    /**
     * 提交订单问题
     */
    @PostMapping("/commitProblem")
    public CommonResult<Integer>commitProblem(@RequestBody OrderProblemCommitRequest request){
        Admin admin = UserUtil.getAdminData();
        int problemId = orderProblemService.commitProblem(request, admin);
        return CommonResult.success(problemId);
    }

    /**
     * 回复
     */
    @PostMapping("/replyProblem")
    public CommonResult replyProblem(@RequestBody OrderProblemReplyRequest request){
        Admin admin = UserUtil.getAdmin();
        orderProblemService.replyProblem(request,admin);
        return CommonResult.success();
    }

    /**
     * 反馈完成
     */
    @GetMapping("/finishProblem")
    public CommonResult finishProblem(@RequestParam(value = "id") Integer id){
       orderProblemService.finishProblem(id);
        return CommonResult.success();
    }

    /**
     * 修改订单问题的跟单处理状态
     */
    @GetMapping("/updateDealStatus")
    public CommonResult updateDealStatus(@RequestParam(value = "id") Integer id,
                                         @RequestParam(value = "dealStatus",required = false) Integer dealStatus){
        orderProblemService.updateDealStatus(id,dealStatus);
        return CommonResult.success();
    }

    /**
     * 修改问题是否加急
     */
    @GetMapping("/updateProblemUrgent")
    public CommonResult updateProblemUrgent(@RequestParam(value = "id") Integer id,
                                         @RequestParam(value = "isUrgent") Integer isUrgent){
        orderProblemService.updateProblemUrgent(id,isUrgent);
        return CommonResult.success();
    }


    /**
     * 订单问题列表
     */
    @PostMapping("/orderProblemList")
    public CommonResult<CommonPage<OrderProblemListResponse>> orderProblemList(@RequestBody OrderProblemListRequest request){
       return CommonResult.success(orderProblemService.orderProblemList(request));
    }

    /**
     * 订单问题详情
     */
    @GetMapping("/orderProblemDetail")
    public CommonResult<OrderProblemDetailResponse> orderProblemDetail(@RequestParam Integer id){
        return orderProblemService.orderProblemDetail(id);
    }

    /**
     * 获取选择接收人 1-客服 2-跟单
     * @param type
     * @return
     */
    @GetMapping("/getReceiveUser")
    public CommonResult<List<Admin>> getReceiveUser(@RequestParam(value = "type") Integer type) {
        return CommonResult.success(orderProblemService.getReceiveUser(type));
    }

    /**
     * 订单问题导出
     */
    @PostMapping("/exportOrderProblemList")
    public CommonResult<List<OrderProblemExportResponse>> exportOrderProblemList(@RequestBody OrderProblemListRequest request){
        return CommonResult.success(orderProblemService.exportOrderProblemList(request));
    }
}
